
package com.cxx.home.controller;

import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.journal.JournalDto;
import com.cxx.home.service.JournalService;
import com.cxx.home.vo.JournalQueryVo;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/journal")
@Tag(name = "日记")
public class JournalController {
    @Resource
    private JournalService journalService;

    @Operation(summary = "查询日记")
    @GetMapping("")
    public @JsonView(ReadView.class) List<JournalDto> queryJournal(JournalQueryVo queryVo) {
        return journalService.queryJournal(queryVo);
    }

    @Operation(summary = "新增日记")
    @PostMapping("")
    public Boolean addAnniversary(@RequestBody @JsonView(WriteView.class) @Validated JournalDto journalDto) {
        return journalService.addJournal(journalDto);
    }

    @Operation(summary = "更新日记")
    @PutMapping("/{id}")
    public Boolean updateAnniversary(@PathVariable("id") long id,
                                     @RequestBody @JsonView(WriteView.class) JournalDto journalDto) {
        return journalService.updateJournal(id, journalDto);
    }

    @Operation(summary = "删除日记")
    @DeleteMapping("/{id}")
    public Boolean deleteAnniversary(@PathVariable("id") long id) {
        return journalService.deleteJournal(id);
    }
}
    